package flinty.autocomplete.combobox.test;

import java.awt.EventQueue;
import java.util.LinkedList;
import java.util.List;

import javax.swing.JComboBox;
import javax.swing.ListCellRenderer;

import flinty.autocomplete.combobox.AutoCompleteComboBoxDecorator;
import flinty.autocomplete.combobox.AutoCompleteComboBoxDecorator.RendererFactory;
import flinty.autocomplete.combobox.DataProvider;
import flinty.autocomplete.combobox.ItemWrapper;
import flinty.autocomplete.combobox.StringConverter;
import flinty.autocomplete.combobox.SimpleListComboBoxModel;

public class SimpleModelApplet extends BaseTestApplet {

	private static final long serialVersionUID = -3035510442721587615L;

	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {

			@Override
			public void run() {
				SimpleModelApplet frame = new SimpleModelApplet();
				frame.setVisible(true);
			}
		});
	}

	@Override
	protected void decorateComboBox(JComboBox combo,
			final LinkedList<Integer> lst) {
		AutoCompleteComboBoxDecorator.decorate(
				combo,
				new SimpleListComboBoxModel<Integer>(
						new DataProvider<Integer>() {

							@Override
							public List<Integer> getData(String pattern) {
								LinkedList<Integer> res = new LinkedList<Integer>();
								res.add(null);
								res.addAll(lst);
								return res;
							}
						}, new StringConverter<Integer>() {

							@Override
							public String render(Integer object) {
								return object != null ? object.toString()
										: null;
							}
						}),
				new RendererFactory() {

					@Override
					public ListCellRenderer createRenderer(
							ListCellRenderer originalRenderer) {
						return originalRenderer;
					}
				},
				new ItemWrapper<Integer>(Integer.valueOf(543221), Integer
						.toString(543221)));
	}

	@Override
	public String getAppletInfo() {
		return "simple list autocomplete demo";
	}
}
